package com.hiyee.customer.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hiyee.api.controller.BaseController;
import com.hiyee.api.controller.customer.ShopControllerApi;
import com.hiyee.customer.mapper.StoreMapper;
import com.hiyee.pojo.Store;
import com.hiyee.response.ResponseJsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

@RestController
public class ShopController extends BaseController implements ShopControllerApi {

    @Autowired
    private StoreMapper storeMapper;

    @Override
    public ResponseJsonResult getShopIndex() throws JsonProcessingException {
        Example example = new Example(Store.class);
        Store store = storeMapper.selectByPrimaryKey(1);
        ObjectMapper objectMapper = new ObjectMapper();
        Object object = objectMapper.readValue(store.getSetting(), Object.class);
        return ResponseJsonResult.success(object);
    }

    @Override
    public ResponseJsonResult getShopSetting() throws JsonProcessingException {
        Example example = new Example(Store.class);
        Store store = storeMapper.selectByPrimaryKey(1);
        ObjectMapper objectMapper = new ObjectMapper();
        Object object = objectMapper.readValue(store.getConfig(), Object.class);
        return ResponseJsonResult.success(object);
    }
}
